#ifndef tlmServiceMsg_H
#define tlmServiceMsg_H

#include "tlmService.h"
//## attribute mInboundMsgBuf
#include "msgbuf.h"
//## attribute mProtocolVersion
#include "tlmServiceElement.h"
//## attribute mDataInfo
class tlmServiceDataInfo;

//## operation SetItsService(tlmServiceApp)
class tlmServiceApp;


//## class tlmServiceMsg
class tlmServiceMsg {

public:
    #define TLM_YEAR_BASE 2000
    
    #define TLM_NGTP_HEADER_CODE_PROTOCOL_VERSION 0x01
    #define TLM_NGTP_HEADER_CODE_VIN  0x02
    #define TLM_NGTP_HEADER_CODE_ROUTE_INFO  0x03
    #define TLM_NGTP_HEADER_CODE_MSG_UNIQUE_ID  0x04
    #define TLM_NGTP_HEADER_CODE_SERVICE_TYPE   0x05
    #define TLM_NGTP_HEADER_CODE_MESSAGE_TYPE   0x06
    #define TLM_NGTP_HEADER_CODE_DATE_TIME      0x07
    #define TLM_NGTP_HEADER_CODE_MSG_PROTOCOL_VERSION   0x08
    #define TLM_NGTP_HEADER_CODE_DATA_LENGTH            0x09

    //this defines the header item count
    #define TLM_NGTP_HEADER_CODE_COUNT 9

public :
    //#[ type de_tlmServiceHeader
    #define TLM_NGTP_HEADER_ONE_BYTE_VALUE_SIZE 1
    
    #define TLM_NGTP_HEADER_TWO_BYTE_VALUE_SIZE 2
    #define TLM_NGTP_HEADER_THREE_BYTE_VALUE_SIZE 3 
    #define TLM_NGTP_HEADER_VIN_VALUE_SIZE 10  
    #define TLM_NGTP_HEADER_DATE_TIME_VALUE_SIZE 4  
    
    //header is fixed length
    #define TLM_NGTP_HEADER_LENGTH   42   
    #define TLM_NGTP_HEADER_ITEM_SRV_TYPE_INCOMING_TRAFFIC TLM_SRV_TYPE_INCOMING_TRAFFIC
    //#]
    
    ////    Friends    ////
    

    ////    Constructors and destructors    ////
    
    
    ////    Operations    ////
    
    //## operation GetData(uint8_t*,uint32_t)
    bool_t GetData(uint8_t* buf, uint32_t size);
    
    //## operation SetData(uint8_t *,uint32_t)
    bool_t SetData(uint8_t * buf, uint32_t size);
    
    //## operation SetValue(uint8_t)
    bool_t SetValue(uint8_t value);
    
    tlmServiceMsg();
    
    //## operation tlmServiceMsg(uint8_t*,uint32_t)
    tlmServiceMsg(const uint8_t* msgString, const uint32_t size);
    
    //## operation tlmServiceMsg(uint8_t,uint8_t)
    tlmServiceMsg(uint8_t srvType, uint8_t msgType);

    tlmServiceMsg(uint8_t srvType, uint8_t msgType, tlmServiceDataInfo*);
    
    //## operation ~tlmServiceMsg()
    ~tlmServiceMsg();
    
    //## operation ParseInit()
    bool_t ParseInit();
    
    //## operation GetValue(uint8_t&)
    bool_t GetValue(uint8_t& value);
    
    //## operation GetHeaderItem(const uint8_t& code)
    tlmServiceElement * GetHeaderItem(const uint8_t& code);
    
    //## operation GetSrvType(uint8_t &) const
    bool_t GetSrvType(uint8_t & srvType) const;
    
    //## operation SetSrvType(uint8_t &)
    bool_t SetSrvType(uint8_t & srvType);
    
    //## operation GetMsgType(uint8_t &) const
    bool_t GetMsgType(uint8_t & msgType) const;
    
    //## operation SetMsgType(uint8_t &)
    bool_t SetMsgType(uint8_t & msgType);
    
    //## operation GetDataInfoLength(uint32_t&) const
    bool_t GetDataInfoLength(uint32_t& dataInfoLen) const;
    
    //## operation SetDataInfoLength(const uint32_t&)
    bool_t SetDataInfoLength(const uint32_t& dataInfoLen);
    
    // This function handle the data info message of incoming message.
    // Parse the data info and initialize component
    //## operation HandleData()
    bool_t HandleData();
    
    //## operation SetDataInfoMsgPtr(uint8_t*)
    void SetDataInfoMsgPtr(uint8_t* ptr);
    
    //## operation Init()
    bool_t Init();
    
    //## operation SetHdrProtocolVersion(uint8_t &)
    bool_t SetHdrProtocolVersion(uint8_t & proVer);
    
    //## operation SetHdrVin(uint8_t *)
    bool_t SetHdrVin(uint8_t * vin);
    
    //## operation SetHdrRoutInfo(uint16_t &)
    bool_t SetHdrRoutInfo(uint16_t & routeInfo);
    
    //## operation SetHdrUniqueId(uint16_t &)
    bool_t SetHdrUniqueId(uint16_t & msgUniqueId);
    
    //## operation SetHdrDateTime(uint32_t &)
    bool_t SetHdrDateTime(uint32_t & dateTime);
    
    //## operation SetHdrMsgProVersion(uint8_t &)
    bool_t SetHdrMsgProVersion(uint8_t & msgProVer);
    
    //## operation Fill()
    bool_t Fill();
    
    //## operation FillHeader()
    bool_t FillHeader();
    
    //## operation GetTotalSize() const
    uint32_t GetTotalSize() const;

	//## operation SetItsService(tlmServiceApp)
    void SetItsService(tlmServiceApp* pSrv);

    //## operation GetOutMsgPtr() const
    uint8_t * GetOutMsgPtr() const;
    //## operation TranslateDateTime(uint8_t*)
    void TranslateDateTime(uint8_t* dateTime);
	//## auto_generated
    uint8_t* getMInMsgPtr() const;
        
    //## auto_generated
    uint8_t* getMOutMsgPtr() const;

    tlmServiceDataInfo* GetDataInfo() const; 

    bool_t GetMsgUniqueId(uint16_t& msgUniqueId) const;
    

    uint8_t GetProtocolVer(void) const;

    uint8_t * GetVin(void) const ;

    uint16_t  GetRouteInfo(void) const;

    uint16_t GetMsgUniqueId(void) const;
    
    uint8_t GetSrvType(void) const;

    uint8_t GetMsgType(void) const ;

    uint32_t  GetYear(void) const;
    
    uint32_t  GetMonth(void) const;

    uint32_t  GetDay(void) const;

    uint32_t  GetHour(void) const;

    uint32_t  GetMinute(void) const;

    uint32_t  GetSecond(void) const;

    uint8_t  GetMsgProtocolVer(void) const;

    uint32_t GetDataInfoLength(void) const;

    uint8_t *  GetDataInfoBuf(void) const;
protected :

    tlmServiceElement mProtocolVersion;		//## attribute mProtocolVersion
    
    tlmServiceElement mVin;		//## attribute mVin
    
    tlmServiceElement mRouteInfo;		//## attribute mRouteInfo
    
    tlmServiceElement mMsgUniqueId;		//## attribute mMsgUniqueId
    
    tlmServiceElement mSrvType;		//## attribute mSrvType
    
    tlmServiceElement mMsgType;		//## attribute mMsgType
    
    tlmServiceElement mDateTime;		//## attribute mDateTime
    
    tlmServiceElement mMsgProtocolVersion;		//## attribute mMsgProtocolVersion
    
    tlmServiceElement mDataLength;		//## attribute mDataLength
    
    msgbuf mInboundMsgBuf;		//## attribute mInboundMsgBuf
    
    msgbuf mOutboundMsgBuf;		//## attribute mOutboundMsgBuf
    
    uint8_t* mInMsgPtr;		//## attribute mInMsgPtr
    
    uint8_t* mOutMsgPtr;		//## attribute mOutMsgPtr
    
    uint32_t mTotalSize;		//## attribute mTotalSize
    
    uint8_t* mDataInfoMsgPtr;		//## attribute mDataInfoMsgPtr
    
    tlmServiceDataInfo* mDataInfo;		//## attribute mDataInfo

	tlmServiceApp* mItsService;         //## attribute mItsSerivce;
};
#endif
